package com.uw.scenic.service.impl;



import com.uw.scenic.entity.User;
import com.uw.scenic.mapper.UserMapper;
import com.uw.scenic.service.UserService;

import com.uw.scenic.exception.GraceException;
import com.uw.scenic.common.ResponseStatusEnum;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.uw.scenic.common.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Title:  UserServiceImpl
 * Description: 请填写描述信息
 * @author yls
 * @created  2023年12月20日 08:56:41 星期三
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User>  implements  UserService{

    @Autowired
    private UserMapper  userMapper;


    @Override
    public ResponseResult  detail(Long id) {
        User user=userMapper.selectById(id);
        return ResponseResult.ok(user);
    }

    @Override
    public ResponseResult  getList() {
        List<User> list=userMapper.selectList(new QueryWrapper<>());
        return ResponseResult.ok(list);
    }

    @Override
    public ResponseResult  getPageList(Integer pageNumber, Integer pageSize) {
        Page<User> pageInfo=new Page(pageNumber,pageSize);
        QueryWrapper<User> queryWrapper=new QueryWrapper<>();
        pageInfo=userMapper.selectPage(pageInfo,queryWrapper);
        return  ResponseResult.ok(pageInfo);
    }

    @Override
    public ResponseResult  saveData(User  user) {
             //创建更新时间
//           sysRole.setCreateDate(new Date());
//           sysRole.setModifyDate(new Date());
             userMapper.insert(user);
             return ResponseResult.ok();
    }

    @Override
    public ResponseResult  update(User  user) {
            User    current=userMapper.selectById(user.getId());
            if(current==null){
                 GraceException.display(ResponseStatusEnum.NOT_FOUND);
            }
            userMapper.updateById(user);
            return ResponseResult.ok();
    }

    @Override
    public ResponseResult  deleteById(Long id) {
          User   current=userMapper.selectById(id);
          if(current==null){
                  GraceException.display(ResponseStatusEnum.NOT_FOUND);
          }
          userMapper.deleteById(id);
          return ResponseResult.ok();
    }


}